package de.homelabs.moonrat.exception;

import java.util.Locale;


public class MoonratException extends Exception {

	private static final long serialVersionUID = 1L;
	private MoonratErrorCode errorCode;
	
	public MoonratException(MoonratErrorCode errorCode){
		this.errorCode = errorCode;
	}
	
	public MoonratException(MoonratErrorCode errorCode, String detailMessage){
		super(detailMessage);
		this.errorCode = errorCode;
	}
	
	public MoonratException(MoonratErrorCode errorCode, Exception e){
		//save underlying exception
		super(e);
		//save errorcode
		this.errorCode = errorCode;
	}
	
	public MoonratErrorCode getErrorCode(){
		return this.errorCode;
	}
	
	public String getErrorCodeLangKey(){
		return this.errorCode.getLangKey();
	}
	
	public String toString(){
		return errorCode.getDefaultMessage() + getMessage();
	}
	
	public String toString(Locale locale){
		//TODO: localization
		return errorCode.getDefaultMessage() + getMessage();
	}
}
